//
//  RootTabBarViewController+UISet.m
//  Demo
//
//  Created by 拓客营 on 2022/3/24.
//

#import "RootTabBarViewController+UISet.h"
#import "HomeViewController.h"
//#import "ShopListViewController.h"
//#import "OrderViewController.h"
#import "MineViewController.h"

NSString *const kHomeImageN = @"icon_tabbar_home_n";
NSString *const kHomeImageS = @"icon_tabbar_home_s";

//NSString *const kListImageN = @"icon_tabbar_Malls_nomal";
//NSString *const kListImageS = @"icon_tabbar_Malls_selected";
//
//NSString *const kOrderImageN = @"icon_tabbar_shoppingCart_nomal";
//NSString *const kOrderImageS = @"icon_tabbar_shoppingCart_selected";

NSString *const kMineImageN = @"icon_tabbar_mine_n";
NSString *const kMineImageS = @"icon_tabbar_mine_s";

@implementation RootTabBarViewController (UISet)

- (void)initialControllers {
    
    [self addChildViewControllers];
    [self hiddenTabbarLine];
    [self setTabBarLayer];
}

- (void)addChildViewControllers {
    
    HomeViewController *homeVC = [[HomeViewController alloc] init];
//    ShopListViewController *listVC = [[ShopListViewController alloc] init];
//    OrderViewController *orderVC = [[OrderViewController alloc] init];
    MineViewController *mineVC    = [[MineViewController alloc] init];
    
    [self addChildTabBarController:homeVC
               navigationItemTitle:@"晋州地质件现货网"
                   tabBarItemTitle:@"首页"
                   tabBarItemImage:kHomeImageN
                     selectedImage:kHomeImageS];
    
//    [self addChildTabBarController:listVC
//               navigationItemTitle:@"商家列表"
//                   tabBarItemTitle:@"商家列表"
//                   tabBarItemImage:kListImageN
//                     selectedImage:kListImageS];
//
//    [self addChildTabBarController:orderVC
//               navigationItemTitle:@"订单"
//                   tabBarItemTitle:@"订单"
//                   tabBarItemImage:kOrderImageN
//                     selectedImage:kOrderImageS];
    
    [self addChildTabBarController:mineVC
               navigationItemTitle:@"会员状态"
                   tabBarItemTitle:@"会员状态"
                   tabBarItemImage:kMineImageN
                     selectedImage:kMineImageS];
    
//    //导航栏title字体
//    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Medium" size:SCALE(18)]}];
    
}

/**  添加子控制器  */
- (void)addChildTabBarController:(UIViewController *)childVC navigationItemTitle:(NSString *)navigationItemTitle tabBarItemTitle:(NSString *)tabBarItemTitle tabBarItemImage:(NSString *)tabBarItemImage selectedImage:(NSString *)selectedImage
{
    
    self.tabBar.unselectedItemTintColor = kRGB(0x7F7F7F);
    self.tabBar.tintColor = kThemeColor;
    
    // tabbar默认颜色
    NSDictionary *textNor = @{NSForegroundColorAttributeName :kRGB(0x7F7F7F), NSFontAttributeName:[UIFont mediumFontOfSize:10]};
    // tabbar选中颜色
    NSDictionary *textSel = @{NSForegroundColorAttributeName :kThemeColor, NSFontAttributeName:[UIFont mediumFontOfSize:10]};

    // 图片不可变
    UIImage *itemNomalImage = [ImageWithName(tabBarItemImage) imageWithRenderingMode: UIImageRenderingModeAutomatic];
    UIImage *itemSelectedImage = [ImageWithName(selectedImage) imageWithRenderingMode: UIImageRenderingModeAutomatic];
    
    UITabBarItem *tabbarItem = [[UITabBarItem alloc] initWithTitle:tabBarItemTitle image:itemNomalImage selectedImage:itemSelectedImage];
    [tabbarItem setTitleTextAttributes:textNor forState:UIControlStateNormal];
    [tabbarItem setTitleTextAttributes:textSel forState:UIControlStateSelected];
    [tabbarItem setTitlePositionAdjustment:UIOffsetMake(0, -3)];
    
    childVC.tabBarItem = tabbarItem;
    
    childVC.navigationItem.title = navigationItemTitle;
    
    //加导航
    BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:childVC];
    [self addChildViewController:nav];
}

- (void)hiddenTabbarLine{
    
    CGRect rect = CGRectMake(0, ScreenHeight-TabBarHeight, ScreenWidth, 1.0);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
    CGContextFillRect(context, rect);
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.tabBar setBackgroundImage:img];
    [self.tabBar setShadowImage:img];
}

- (void)setTabBarLayer
{
    [self.tabBar.layer setShadowColor:kRGBA(0x222222, 0.03).CGColor];
    [self.tabBar.layer setShadowOffset:CGSizeMake(-1.5,-1.5)];
    [self.tabBar.layer setShadowOpacity:1.0];
    [self.tabBar.layer setShadowRadius:4.0];
}

@end
